{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Working with index"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Content\n",
    "* [Index types](#Index-types)\n",
    "* [How to create an index](#How-to-create-an-index)\n",
    "    * [from SEGY files](#from-SEGY-files)\n",
    "    * [from SPS files](#from-SPS-files)\n",
    "* [Filtration](#Filtration)\n",
    "* [Conversion between types](#Conversion-between-types)\n",
    "* [Merge](#Merge)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Index types"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are 5 basic types of indices:\n",
    "* ```TraceIndex``` enumerates individual traces\n",
    "* ```FieldIndex``` enumerates field records\n",
    "* ```SegyFilesIndex``` enumerates SEGY files\n",
    "* ```BinsIndex``` enumerated bins of regular grid\n",
    "* ```KNNIndex``` enumerated groups of k nearest traces\n",
    "\n",
    "and ```CustomIndex``` that enables enumeration on a basis of any ```segyio.TraceField``` attribute, e.g. ```INLINE_3D``` or ```ShotPoint```.\n",
    "\n",
    "There is an easy convertion between index types. Let ```index``` be an instance of some intex type, then  ```FieldIndex(index)``` will be an instance of type ```FieldIndex```, while ```TraceIndex(index)``` will be an instance of type ```TraceIndex``` etc.\n",
    "\n",
    "Index can be created from a single SEGY file, from multiple SEGY files and from SPS files. Index can be merged with another one index. Below we illustrate these options. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## How to create an index"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### from SEGY files"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We start with a single SEGY file and create a ```TraceIndex```. It requieres path to the file and name that we will assosiate with traces:   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "sys.path.append('..')\n",
    "from seismicpro.src import (FieldIndex, TraceIndex, SegyFilesIndex, BinsIndex,\n",
    "                            CustomIndex, KNNIndex)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "path_raw = '/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy'\n",
    "index_trace = TraceIndex(name='raw', path=path_raw)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```head()``` shows 5 first traces (similar to pandas):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>FieldRecord</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1656</td>\n",
       "      <td>111906</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1657</td>\n",
       "      <td>111906</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1655</td>\n",
       "      <td>111906</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1658</td>\n",
       "      <td>111906</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1654</td>\n",
       "      <td>111906</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  TraceNumber FieldRecord TRACE_SEQUENCE_FILE  \\\n",
       "                                          raw   \n",
       "0        1656      111906                   1   \n",
       "1        1657      111906                   2   \n",
       "2        1655      111906                   3   \n",
       "3        1658      111906                   4   \n",
       "4        1654      111906                   5   \n",
       "\n",
       "                                           file_id  \n",
       "                                               raw  \n",
       "0  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "1  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "2  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "3  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "4  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_trace.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note the index contains columns ```TraceNumber``` and ```FieldRecord``` that uniquely define seismic traces. ```TRACE_SEQUENCE_FILE``` gives a trace location within the file. To include more columns , use ```extra_headers``` argument (or set ```extra_headers='all'``` to include all available headers):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>offset</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>FieldRecord</th>\n",
       "      <th>ShotPoint</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>35</td>\n",
       "      <td>1656</td>\n",
       "      <td>111906</td>\n",
       "      <td>42000</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>36</td>\n",
       "      <td>1657</td>\n",
       "      <td>111906</td>\n",
       "      <td>42000</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>78</td>\n",
       "      <td>1655</td>\n",
       "      <td>111906</td>\n",
       "      <td>42000</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>79</td>\n",
       "      <td>1658</td>\n",
       "      <td>111906</td>\n",
       "      <td>42000</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>127</td>\n",
       "      <td>1654</td>\n",
       "      <td>111906</td>\n",
       "      <td>42000</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  offset TraceNumber FieldRecord ShotPoint TRACE_SEQUENCE_FILE  \\\n",
       "                                                           raw   \n",
       "0     35        1656      111906     42000                   1   \n",
       "1     36        1657      111906     42000                   2   \n",
       "2     78        1655      111906     42000                   3   \n",
       "3     79        1658      111906     42000                   4   \n",
       "4    127        1654      111906     42000                   5   \n",
       "\n",
       "                                           file_id  \n",
       "                                               raw  \n",
       "0  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "1  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "2  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "3  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "4  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_trace = TraceIndex(name='raw', path=path_raw, extra_headers=['ShotPoint', 'offset'])\n",
    "index_trace.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the next example we will create an index of field records from a set of SEGY files:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FieldRecord</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>3</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            TraceNumber TRACE_SEQUENCE_FILE  \\\n",
       "                                        raw   \n",
       "FieldRecord                                   \n",
       "354                   1                   1   \n",
       "354                   2                   2   \n",
       "354                   1                   3   \n",
       "354                   2                   4   \n",
       "354                   3                   5   \n",
       "\n",
       "                                                       file_id  \n",
       "                                                           raw  \n",
       "FieldRecord                                                     \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_ffid = FieldIndex(name='raw', path='/data/NA/2D_Val/prof_37/segy/*.sgy')         \n",
    "index_ffid.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that SEGY files contain auxiliary traces and we obtain duplicated (FieldRecord, TraceNumber) pairs in the index. This can be checked with ```duplicated``` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.any(index_ffid.duplicated())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Method ```drop_duplicated``` helps to remove auxiliary traces:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FieldRecord</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>3</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            TraceNumber TRACE_SEQUENCE_FILE  \\\n",
       "                                        raw   \n",
       "FieldRecord                                   \n",
       "354                   1                   3   \n",
       "354                   2                   4   \n",
       "354                   3                   5   \n",
       "354                   4                   6   \n",
       "354                   5                   7   \n",
       "\n",
       "                                                       file_id  \n",
       "                                                           raw  \n",
       "FieldRecord                                                     \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_ffid = index_ffid.drop_duplicates(keep='last')\n",
    "index_ffid.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we assume iteration over files, we create a ```SegyFilesIndex``` in a similar way:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>FieldRecord</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(file_id, raw)</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</th>\n",
       "      <td>1</td>\n",
       "      <td>354</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</th>\n",
       "      <td>2</td>\n",
       "      <td>354</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</th>\n",
       "      <td>1</td>\n",
       "      <td>354</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</th>\n",
       "      <td>2</td>\n",
       "      <td>354</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</th>\n",
       "      <td>3</td>\n",
       "      <td>354</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  TraceNumber FieldRecord  \\\n",
       "                                                                            \n",
       "(file_id, raw)                                                              \n",
       "/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy           1         354   \n",
       "/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy           2         354   \n",
       "/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy           1         354   \n",
       "/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy           2         354   \n",
       "/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy           3         354   \n",
       "\n",
       "                                                  TRACE_SEQUENCE_FILE  \n",
       "                                                                  raw  \n",
       "(file_id, raw)                                                         \n",
       "/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy                   1  \n",
       "/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy                   2  \n",
       "/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy                   3  \n",
       "/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy                   4  \n",
       "/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy                   5  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_files = SegyFilesIndex(name='raw', path='/data/NA/2D_Val/prof_37/segy/*.sgy')          \n",
    "index_files.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To make things more flexible, there is a ```CustomIndex``` that allows iteration by any ```segyio.TraceField``` attribute, e.g. ```INLINE_3D```, ```ShotPoint```, ```CDP``` etc. For example, let's create an index of shot points:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>FieldRecord</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ShotPoint</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>42000</th>\n",
       "      <td>1656</td>\n",
       "      <td>111906</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42000</th>\n",
       "      <td>1657</td>\n",
       "      <td>111906</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42000</th>\n",
       "      <td>1655</td>\n",
       "      <td>111906</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42000</th>\n",
       "      <td>1658</td>\n",
       "      <td>111906</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42000</th>\n",
       "      <td>1654</td>\n",
       "      <td>111906</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          TraceNumber FieldRecord TRACE_SEQUENCE_FILE  \\\n",
       "                                                  raw   \n",
       "ShotPoint                                               \n",
       "42000            1656      111906                   1   \n",
       "42000            1657      111906                   2   \n",
       "42000            1655      111906                   3   \n",
       "42000            1658      111906                   4   \n",
       "42000            1654      111906                   5   \n",
       "\n",
       "                                                   file_id  \n",
       "                                                       raw  \n",
       "ShotPoint                                                   \n",
       "42000      /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "42000      /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "42000      /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "42000      /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "42000      /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_shot = CustomIndex(name='raw', index_name='ShotPoint', path=path_raw)\n",
    "index_shot.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, there is a```KNNIndex``` that enumerates groups of k nearest located traces based on its ```CDP_X``` and ```CDP_Y``` attributes: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>FieldRecord</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>CDP_X</th>\n",
       "      <th>CDP_Y</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>KNN</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>111906</td>\n",
       "      <td>1656</td>\n",
       "      <td>499279</td>\n",
       "      <td>6639805</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>111906</td>\n",
       "      <td>1657</td>\n",
       "      <td>499304</td>\n",
       "      <td>6639805</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>111906</td>\n",
       "      <td>1655</td>\n",
       "      <td>499254</td>\n",
       "      <td>6639805</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>111906</td>\n",
       "      <td>1657</td>\n",
       "      <td>499304</td>\n",
       "      <td>6639805</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>111906</td>\n",
       "      <td>1656</td>\n",
       "      <td>499279</td>\n",
       "      <td>6639805</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>111906</td>\n",
       "      <td>1658</td>\n",
       "      <td>499329</td>\n",
       "      <td>6639805</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>111906</td>\n",
       "      <td>1655</td>\n",
       "      <td>499254</td>\n",
       "      <td>6639805</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>111906</td>\n",
       "      <td>1656</td>\n",
       "      <td>499279</td>\n",
       "      <td>6639805</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>111906</td>\n",
       "      <td>1654</td>\n",
       "      <td>499229</td>\n",
       "      <td>6639805</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    FieldRecord TraceNumber   CDP_X    CDP_Y TRACE_SEQUENCE_FILE  \\\n",
       "                                                             raw   \n",
       "KNN                                                                \n",
       "0        111906        1656  499279  6639805                   1   \n",
       "0        111906        1657  499304  6639805                   2   \n",
       "0        111906        1655  499254  6639805                   3   \n",
       "1        111906        1657  499304  6639805                   2   \n",
       "1        111906        1656  499279  6639805                   1   \n",
       "1        111906        1658  499329  6639805                   4   \n",
       "2        111906        1655  499254  6639805                   3   \n",
       "2        111906        1656  499279  6639805                   1   \n",
       "2        111906        1654  499229  6639805                   5   \n",
       "\n",
       "                                             file_id  \n",
       "                                                 raw  \n",
       "KNN                                                   \n",
       "0    /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "0    /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "0    /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "1    /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "1    /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "1    /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "2    /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "2    /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "2    /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_knn = KNNIndex(name='raw', n_neighbors=3, path=path_raw)\n",
    "index_knn.head(9)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### from SPS files"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```TraceIndex``` and ```FieldIndex``` can be alternatively constructed from SPS files. As a by-product, it will include offsets, azimuth and a number of other metadata: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>sline</th>\n",
       "      <th>sid</th>\n",
       "      <th>rline</th>\n",
       "      <th>rid</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>point_index</th>\n",
       "      <th>sht_depth</th>\n",
       "      <th>uphole</th>\n",
       "      <th>SourceX</th>\n",
       "      <th>SourceY</th>\n",
       "      <th>z_s</th>\n",
       "      <th>x_r</th>\n",
       "      <th>y_r</th>\n",
       "      <th>z_r</th>\n",
       "      <th>CDP_X</th>\n",
       "      <th>CDP_Y</th>\n",
       "      <th>azimuth</th>\n",
       "      <th>offset</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FieldRecord</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>S37</td>\n",
       "      <td>3591</td>\n",
       "      <td>R37</td>\n",
       "      <td>290</td>\n",
       "      <td>72</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>338886.78</td>\n",
       "      <td>7033413.0</td>\n",
       "      <td>71.5</td>\n",
       "      <td>338725.94</td>\n",
       "      <td>7031696.5</td>\n",
       "      <td>87.8</td>\n",
       "      <td>338806.360</td>\n",
       "      <td>7032554.75</td>\n",
       "      <td>-1.664226</td>\n",
       "      <td>862.009535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>S37</td>\n",
       "      <td>3591</td>\n",
       "      <td>R37</td>\n",
       "      <td>367</td>\n",
       "      <td>149</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>338886.78</td>\n",
       "      <td>7033413.0</td>\n",
       "      <td>71.5</td>\n",
       "      <td>338905.56</td>\n",
       "      <td>7033612.0</td>\n",
       "      <td>69.9</td>\n",
       "      <td>338896.170</td>\n",
       "      <td>7033512.50</td>\n",
       "      <td>1.476703</td>\n",
       "      <td>99.942094</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>S37</td>\n",
       "      <td>3591</td>\n",
       "      <td>R37</td>\n",
       "      <td>368</td>\n",
       "      <td>150</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>338886.78</td>\n",
       "      <td>7033413.0</td>\n",
       "      <td>71.5</td>\n",
       "      <td>338907.88</td>\n",
       "      <td>7033637.0</td>\n",
       "      <td>70.2</td>\n",
       "      <td>338897.330</td>\n",
       "      <td>7033525.00</td>\n",
       "      <td>1.476877</td>\n",
       "      <td>112.495789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>S37</td>\n",
       "      <td>3591</td>\n",
       "      <td>R37</td>\n",
       "      <td>419</td>\n",
       "      <td>201</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>338886.78</td>\n",
       "      <td>7033413.0</td>\n",
       "      <td>71.5</td>\n",
       "      <td>339027.12</td>\n",
       "      <td>7034906.0</td>\n",
       "      <td>67.8</td>\n",
       "      <td>338956.950</td>\n",
       "      <td>7034159.50</td>\n",
       "      <td>1.477073</td>\n",
       "      <td>749.790690</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>S37</td>\n",
       "      <td>3591</td>\n",
       "      <td>R37</td>\n",
       "      <td>485</td>\n",
       "      <td>267</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>338886.78</td>\n",
       "      <td>7033413.0</td>\n",
       "      <td>71.5</td>\n",
       "      <td>339181.25</td>\n",
       "      <td>7036547.5</td>\n",
       "      <td>64.8</td>\n",
       "      <td>339034.015</td>\n",
       "      <td>7034980.25</td>\n",
       "      <td>1.477126</td>\n",
       "      <td>1574.150789</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            sline   sid rline  rid TraceNumber point_index sht_depth uphole  \\\n",
       "                                                                              \n",
       "FieldRecord                                                                   \n",
       "354           S37  3591   R37  290          72           1      18.0   14.0   \n",
       "354           S37  3591   R37  367         149           1      18.0   14.0   \n",
       "354           S37  3591   R37  368         150           1      18.0   14.0   \n",
       "354           S37  3591   R37  419         201           1      18.0   14.0   \n",
       "354           S37  3591   R37  485         267           1      18.0   14.0   \n",
       "\n",
       "               SourceX    SourceY   z_s        x_r        y_r   z_r  \\\n",
       "                                                                      \n",
       "FieldRecord                                                           \n",
       "354          338886.78  7033413.0  71.5  338725.94  7031696.5  87.8   \n",
       "354          338886.78  7033413.0  71.5  338905.56  7033612.0  69.9   \n",
       "354          338886.78  7033413.0  71.5  338907.88  7033637.0  70.2   \n",
       "354          338886.78  7033413.0  71.5  339027.12  7034906.0  67.8   \n",
       "354          338886.78  7033413.0  71.5  339181.25  7036547.5  64.8   \n",
       "\n",
       "                  CDP_X       CDP_Y   azimuth       offset  \n",
       "                                                            \n",
       "FieldRecord                                                 \n",
       "354          338806.360  7032554.75 -1.664226   862.009535  \n",
       "354          338896.170  7033512.50  1.476703    99.942094  \n",
       "354          338897.330  7033525.00  1.476877   112.495789  \n",
       "354          338956.950  7034159.50  1.477073   749.790690  \n",
       "354          339034.015  7034980.25  1.477126  1574.150789  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfx = pd.read_csv('/data/NA/2D_Val/sps/ALL_VALUNT0910_X37.csv')\n",
    "dfr = pd.read_csv('/data/NA/2D_Val/sps/ALL_VALUNT0910_R_utm.csv')\n",
    "dfs = pd.read_csv('/data/NA/2D_Val/sps/ALL_VALUNT0910_S_utm.csv')\n",
    "\n",
    "index_sps = FieldIndex(dfx=dfx, dfr=dfr, dfs=dfs)\n",
    "index_sps.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To create a ```Binsindex``` one should specify ```bin_size```. If grid position is not provided it will be optimized during index construction: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>FieldRecord</th>\n",
       "      <th>sline</th>\n",
       "      <th>sid</th>\n",
       "      <th>rline</th>\n",
       "      <th>rid</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>SourceX</th>\n",
       "      <th>SourceY</th>\n",
       "      <th>z_s</th>\n",
       "      <th>x_r</th>\n",
       "      <th>y_r</th>\n",
       "      <th>z_r</th>\n",
       "      <th>CDP_X</th>\n",
       "      <th>CDP_Y</th>\n",
       "      <th>azimuth</th>\n",
       "      <th>offset</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bin_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1/16</th>\n",
       "      <td>327541Z</td>\n",
       "      <td>S2305</td>\n",
       "      <td>5598</td>\n",
       "      <td>R5601</td>\n",
       "      <td>2319</td>\n",
       "      <td>439</td>\n",
       "      <td>503985.5</td>\n",
       "      <td>6630966.5</td>\n",
       "      <td>37.9</td>\n",
       "      <td>504710.4</td>\n",
       "      <td>6631092.0</td>\n",
       "      <td>37.9</td>\n",
       "      <td>504347.95</td>\n",
       "      <td>6631029.25</td>\n",
       "      <td>0.171428</td>\n",
       "      <td>367.841766</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1/16</th>\n",
       "      <td>327521Z</td>\n",
       "      <td>S2305</td>\n",
       "      <td>5597</td>\n",
       "      <td>R5601</td>\n",
       "      <td>2305</td>\n",
       "      <td>425</td>\n",
       "      <td>503985.5</td>\n",
       "      <td>6630917.0</td>\n",
       "      <td>38.1</td>\n",
       "      <td>504010.7</td>\n",
       "      <td>6631092.0</td>\n",
       "      <td>38.1</td>\n",
       "      <td>503998.10</td>\n",
       "      <td>6631004.50</td>\n",
       "      <td>1.427779</td>\n",
       "      <td>88.402545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1/16</th>\n",
       "      <td>327541Z</td>\n",
       "      <td>S2305</td>\n",
       "      <td>5598</td>\n",
       "      <td>R5601</td>\n",
       "      <td>2305</td>\n",
       "      <td>425</td>\n",
       "      <td>503985.5</td>\n",
       "      <td>6630966.5</td>\n",
       "      <td>37.9</td>\n",
       "      <td>504010.7</td>\n",
       "      <td>6631092.0</td>\n",
       "      <td>38.1</td>\n",
       "      <td>503998.10</td>\n",
       "      <td>6631029.25</td>\n",
       "      <td>1.372635</td>\n",
       "      <td>64.002519</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1/16</th>\n",
       "      <td>327561Z</td>\n",
       "      <td>S2305</td>\n",
       "      <td>5599</td>\n",
       "      <td>R5601</td>\n",
       "      <td>2305</td>\n",
       "      <td>425</td>\n",
       "      <td>503985.5</td>\n",
       "      <td>6631016.5</td>\n",
       "      <td>38.0</td>\n",
       "      <td>504010.7</td>\n",
       "      <td>6631092.0</td>\n",
       "      <td>38.1</td>\n",
       "      <td>503998.10</td>\n",
       "      <td>6631054.25</td>\n",
       "      <td>1.248648</td>\n",
       "      <td>39.797267</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1/16</th>\n",
       "      <td>327581Z</td>\n",
       "      <td>S2305</td>\n",
       "      <td>5600</td>\n",
       "      <td>R5601</td>\n",
       "      <td>2305</td>\n",
       "      <td>425</td>\n",
       "      <td>503985.5</td>\n",
       "      <td>6631066.5</td>\n",
       "      <td>38.0</td>\n",
       "      <td>504010.7</td>\n",
       "      <td>6631092.0</td>\n",
       "      <td>38.1</td>\n",
       "      <td>503998.10</td>\n",
       "      <td>6631079.25</td>\n",
       "      <td>0.791315</td>\n",
       "      <td>17.925471</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       FieldRecord  sline   sid  rline   rid TraceNumber   SourceX    SourceY  \\\n",
       "                                                                                \n",
       "bin_id                                                                          \n",
       "1/16       327541Z  S2305  5598  R5601  2319         439  503985.5  6630966.5   \n",
       "1/16       327521Z  S2305  5597  R5601  2305         425  503985.5  6630917.0   \n",
       "1/16       327541Z  S2305  5598  R5601  2305         425  503985.5  6630966.5   \n",
       "1/16       327561Z  S2305  5599  R5601  2305         425  503985.5  6631016.5   \n",
       "1/16       327581Z  S2305  5600  R5601  2305         425  503985.5  6631066.5   \n",
       "\n",
       "         z_s       x_r        y_r   z_r      CDP_X       CDP_Y   azimuth  \\\n",
       "                                                                           \n",
       "bin_id                                                                     \n",
       "1/16    37.9  504710.4  6631092.0  37.9  504347.95  6631029.25  0.171428   \n",
       "1/16    38.1  504010.7  6631092.0  38.1  503998.10  6631004.50  1.427779   \n",
       "1/16    37.9  504010.7  6631092.0  38.1  503998.10  6631029.25  1.372635   \n",
       "1/16    38.0  504010.7  6631092.0  38.1  503998.10  6631054.25  1.248648   \n",
       "1/16    38.0  504010.7  6631092.0  38.1  503998.10  6631079.25  0.791315   \n",
       "\n",
       "            offset  \n",
       "                    \n",
       "bin_id              \n",
       "1/16    367.841766  \n",
       "1/16     88.402545  \n",
       "1/16     64.002519  \n",
       "1/16     39.797267  \n",
       "1/16     17.925471  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfx = pd.read_csv('/data/NA/Xfield/Xfield_X.csv')\n",
    "dfr = pd.read_csv('/data/NA/Xfield/Xfield_R.csv')\n",
    "dfs = pd.read_csv('/data/NA/Xfield/Xfield_S.csv')\n",
    "\n",
    "bin_size = 1000\n",
    "\n",
    "index_bin = BinsIndex(dfr=dfr, dfs=dfs, dfx=dfx, bin_size=(bin_size, bin_size), max_iters=10)\n",
    "index_bin.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The heatmap shows a distribution of traces within bins:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVoAAAEKCAYAAABT352BAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3X+YXVV97/H3ZyYJ4XcSwQhJNChRG2kFiRCLvSIoBNsabDGFWoleSnwuUNFqW/Taogh90Eel+FTTjiWX4FVCRCipDcQ04qW25Uf4IRACMoUgyRMIkB8gmJCZ+d4/9jrmEM/e58zM2XPOmfm8ePYz56y11z5rDme+2Wft715LEYGZmZWnq9UdMDMb7RxozcxK5kBrZlYyB1ozs5I50JqZlcyB1sysZA60ZmYlc6A1MyuZA62ZWcnGtboDjZigfWIi+5dybHV3F1SqlNccjaK/v84OvgNxtNrJi7wcu4b1x3Lqu/eP57bW+Qwld9+/a1VEzBvO6420jgi0E9mf43Xy0BrXCZbdB0/KrxzXEW9PWxh4/vnC+ti1a4R6YiPtjlgz7GM8t7WfO1e9tqF9uw979JBhv+AIcyQxs5YLYICBVnejNA60ZtZyQbA7Ghs66ES+GGZmbWGgwf8aIemTktZJelDStZImSjpC0h2SeiVdJ2lC2nef9Lw31c+sOs5nUvkjkk6tKp+XynolXVSvPw60ZtZyQdAfjW31SJoGfByYExFHAd3AmcCXgCsi4khgG3BOanIOsC2VX5H2Q9Ls1O4twDzgm5K6JXUD3wBOA2YDZ6V9cznQmllbGCAa2ho0DthX0jhgP2AzcBJwfapfCpyeHs9Pz0n1J0tSKl8WEbsi4nGgFzgubb0R8VhEvAwsS/vmcqA1s5YLoJ9oaKt7rIhNwFeAn5MF2B3A3cD2iOhLu20EpqXH04AnU9u+tP+rqsv3apNXnmtUXAzT+Am5dTs++LbCt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B6WngYuCfgeXAa8lmP1sQESN6YSqnXyeSfQ0OYAPwsaqx0ZHo0zuBfwceACoTnH6WbDy0Ze9XQb/OokXvl6TfIrvY1U12YrY8Ii5Jn/tlwBTgXuBPIsJLoeToqEBrZtaJOmnowMysIznQmpmVzIHWzKxkDrRmZiVzoDUzK5kDrZVmr1mnHpa0WFJXqrtE0nta3UezkeBAa2W7It2+ORv4TeBdABHxNxHxby3tmdkIcaC1IZH09jTJycR0d9w6SUcVNJlAtkz0ttT+amXLQlfm8/2CpHuUzev75lT+rqo5WO+t3IFn1mkcaG1IIuIusltWLwW+DPzfiKh1a+gn08xPm4GfRcR9OYd8Nk3Msxj4dCr7NHB+OiP+HeCXzfwdzEaKA60NxyVk977PIQu2tVSGDl4N7C/pzJz9KhO73A3MTI//A/iapI8Dk6qm5TPrKA60NhyvAg4ADgQmSrqs8lV/7x0jYjdwC5A3hWTlPvl+0urMEXE58KfAvsB/VIYUzDpNpy43bu3hH4G/Bo4AvhQRFwD/u9aOaWaqE8gmIGmIpDdExAPAA5LeTjYP6sPD7rXZCPMZrQ2JpLOB3RHxXeBy4O2STqqxa2WM9kGyGaC+OYiX+YSkByXdD+wGbh5uv81awbN3mZmVzGe0ZmYlc6A1MyuZA62ZWckcaM3MSuZAa2ZWMgdaM7OSOdCamZXMgdbMrGT/Hw2pKOJuJOA3AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "index_bin.show_heatmap()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Filtration\n",
    "\n",
    "One can filter indexed traces by some criteria. For example, we can keep only traces with offsets less than 100 as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>offset</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>FieldRecord</th>\n",
       "      <th>ShotPoint</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>35</td>\n",
       "      <td>1656</td>\n",
       "      <td>111906</td>\n",
       "      <td>42000</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>36</td>\n",
       "      <td>1657</td>\n",
       "      <td>111906</td>\n",
       "      <td>42000</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>78</td>\n",
       "      <td>1655</td>\n",
       "      <td>111906</td>\n",
       "      <td>42000</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>79</td>\n",
       "      <td>1658</td>\n",
       "      <td>111906</td>\n",
       "      <td>42000</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3456</th>\n",
       "      <td>35</td>\n",
       "      <td>1801</td>\n",
       "      <td>111907</td>\n",
       "      <td>42001</td>\n",
       "      <td>3457</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     offset TraceNumber FieldRecord ShotPoint TRACE_SEQUENCE_FILE  \\\n",
       "                                                              raw   \n",
       "0        35        1656      111906     42000                   1   \n",
       "1        36        1657      111906     42000                   2   \n",
       "2        78        1655      111906     42000                   3   \n",
       "3        79        1658      111906     42000                   4   \n",
       "3456     35        1801      111907     42001                3457   \n",
       "\n",
       "                                              file_id  \n",
       "                                                  raw  \n",
       "0     /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "1     /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "2     /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "3     /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "3456  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filtered_index = index_trace.filter('offset', lambda x: x < 100)\n",
    "filtered_index.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "More complex criteria are also supported. Below we keep in index only traces with offset below 100 and TraceNumber not less that 42002:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>offset</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>FieldRecord</th>\n",
       "      <th>ShotPoint</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>6912</th>\n",
       "      <td>35</td>\n",
       "      <td>1800</td>\n",
       "      <td>111908</td>\n",
       "      <td>42002</td>\n",
       "      <td>6913</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6913</th>\n",
       "      <td>35</td>\n",
       "      <td>1801</td>\n",
       "      <td>111908</td>\n",
       "      <td>42002</td>\n",
       "      <td>6914</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6914</th>\n",
       "      <td>79</td>\n",
       "      <td>1799</td>\n",
       "      <td>111908</td>\n",
       "      <td>42002</td>\n",
       "      <td>6915</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6915</th>\n",
       "      <td>79</td>\n",
       "      <td>1802</td>\n",
       "      <td>111908</td>\n",
       "      <td>42002</td>\n",
       "      <td>6916</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10368</th>\n",
       "      <td>35</td>\n",
       "      <td>1800</td>\n",
       "      <td>111909</td>\n",
       "      <td>42003</td>\n",
       "      <td>10369</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      offset TraceNumber FieldRecord ShotPoint TRACE_SEQUENCE_FILE  \\\n",
       "                                                               raw   \n",
       "6912      35        1800      111908     42002                6913   \n",
       "6913      35        1801      111908     42002                6914   \n",
       "6914      79        1799      111908     42002                6915   \n",
       "6915      79        1802      111908     42002                6916   \n",
       "10368     35        1800      111909     42003               10369   \n",
       "\n",
       "                                               file_id  \n",
       "                                                   raw  \n",
       "6912   /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "6913   /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "6914   /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "6915   /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "10368  /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filtered_index = index_trace.filter(['offset', 'ShotPoint'],\n",
    "                                    lambda x: (x[0] < 100) & (x[1] >= 42002))\n",
    "filtered_index.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Conversion between types"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Index can be easily converted to other index type. For example, ```FieldIndex``` to ```TraceIndex```:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>FieldRecord</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>354</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>354</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>354</td>\n",
       "      <td>3</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>354</td>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>354</td>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  FieldRecord TraceNumber TRACE_SEQUENCE_FILE  \\\n",
       "                                          raw   \n",
       "0         354           1                   3   \n",
       "1         354           2                   4   \n",
       "2         354           3                   5   \n",
       "3         354           4                   6   \n",
       "4         354           5                   7   \n",
       "\n",
       "                                             file_id  \n",
       "                                                 raw  \n",
       "0  /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "1  /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "2  /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "3  /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  \n",
       "4  /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "TraceIndex(index_ffid).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or vise-versa:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>offset</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>ShotPoint</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FieldRecord</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>35</td>\n",
       "      <td>1656</td>\n",
       "      <td>42000</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>36</td>\n",
       "      <td>1657</td>\n",
       "      <td>42000</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>78</td>\n",
       "      <td>1655</td>\n",
       "      <td>42000</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>79</td>\n",
       "      <td>1658</td>\n",
       "      <td>42000</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>127</td>\n",
       "      <td>1654</td>\n",
       "      <td>42000</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            offset TraceNumber ShotPoint TRACE_SEQUENCE_FILE  \\\n",
       "                                                         raw   \n",
       "FieldRecord                                                    \n",
       "111906          35        1656     42000                   1   \n",
       "111906          36        1657     42000                   2   \n",
       "111906          78        1655     42000                   3   \n",
       "111906          79        1658     42000                   4   \n",
       "111906         127        1654     42000                   5   \n",
       "\n",
       "                                                     file_id  \n",
       "                                                         raw  \n",
       "FieldRecord                                                   \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "FieldIndex(index_trace).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or ```BinsIndex``` to ```FieldIndex```:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>bin_id</th>\n",
       "      <th>sline</th>\n",
       "      <th>sid</th>\n",
       "      <th>rline</th>\n",
       "      <th>rid</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>SourceX</th>\n",
       "      <th>SourceY</th>\n",
       "      <th>z_s</th>\n",
       "      <th>x_r</th>\n",
       "      <th>y_r</th>\n",
       "      <th>z_r</th>\n",
       "      <th>CDP_X</th>\n",
       "      <th>CDP_Y</th>\n",
       "      <th>azimuth</th>\n",
       "      <th>offset</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FieldRecord</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10001Z</th>\n",
       "      <td>17/20</td>\n",
       "      <td>S2417</td>\n",
       "      <td>5284</td>\n",
       "      <td>R5289</td>\n",
       "      <td>2362</td>\n",
       "      <td>746</td>\n",
       "      <td>509583.9</td>\n",
       "      <td>6615273.0</td>\n",
       "      <td>38.1</td>\n",
       "      <td>506859.4</td>\n",
       "      <td>6615497.5</td>\n",
       "      <td>39.9</td>\n",
       "      <td>508221.65</td>\n",
       "      <td>6615385.25</td>\n",
       "      <td>3.059378</td>\n",
       "      <td>1366.866901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10001Z</th>\n",
       "      <td>17/22</td>\n",
       "      <td>S2417</td>\n",
       "      <td>5284</td>\n",
       "      <td>R5277</td>\n",
       "      <td>2427</td>\n",
       "      <td>587</td>\n",
       "      <td>509583.9</td>\n",
       "      <td>6615273.0</td>\n",
       "      <td>38.1</td>\n",
       "      <td>510108.2</td>\n",
       "      <td>6614898.0</td>\n",
       "      <td>36.9</td>\n",
       "      <td>509846.05</td>\n",
       "      <td>6615085.50</td>\n",
       "      <td>-0.620881</td>\n",
       "      <td>322.302455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10001Z</th>\n",
       "      <td>18/21</td>\n",
       "      <td>S2417</td>\n",
       "      <td>5284</td>\n",
       "      <td>R5247</td>\n",
       "      <td>2410</td>\n",
       "      <td>50</td>\n",
       "      <td>509583.9</td>\n",
       "      <td>6615273.0</td>\n",
       "      <td>38.1</td>\n",
       "      <td>509258.8</td>\n",
       "      <td>6613398.5</td>\n",
       "      <td>35.4</td>\n",
       "      <td>509421.35</td>\n",
       "      <td>6614335.75</td>\n",
       "      <td>-1.742521</td>\n",
       "      <td>951.241328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10001Z</th>\n",
       "      <td>17/22</td>\n",
       "      <td>S2417</td>\n",
       "      <td>5284</td>\n",
       "      <td>R5289</td>\n",
       "      <td>2424</td>\n",
       "      <td>808</td>\n",
       "      <td>509583.9</td>\n",
       "      <td>6615273.0</td>\n",
       "      <td>38.1</td>\n",
       "      <td>509958.3</td>\n",
       "      <td>6615497.5</td>\n",
       "      <td>37.3</td>\n",
       "      <td>509771.10</td>\n",
       "      <td>6615385.25</td>\n",
       "      <td>0.540145</td>\n",
       "      <td>218.274832</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10001Z</th>\n",
       "      <td>17/23</td>\n",
       "      <td>S2417</td>\n",
       "      <td>5284</td>\n",
       "      <td>R5277</td>\n",
       "      <td>2455</td>\n",
       "      <td>615</td>\n",
       "      <td>509583.9</td>\n",
       "      <td>6615273.0</td>\n",
       "      <td>38.1</td>\n",
       "      <td>511507.9</td>\n",
       "      <td>6614898.0</td>\n",
       "      <td>34.8</td>\n",
       "      <td>510545.90</td>\n",
       "      <td>6615085.50</td>\n",
       "      <td>-0.192493</td>\n",
       "      <td>980.102163</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            bin_id  sline   sid  rline   rid TraceNumber   SourceX    SourceY  \\\n",
       "                                                                                \n",
       "FieldRecord                                                                     \n",
       "10001Z       17/20  S2417  5284  R5289  2362         746  509583.9  6615273.0   \n",
       "10001Z       17/22  S2417  5284  R5277  2427         587  509583.9  6615273.0   \n",
       "10001Z       18/21  S2417  5284  R5247  2410          50  509583.9  6615273.0   \n",
       "10001Z       17/22  S2417  5284  R5289  2424         808  509583.9  6615273.0   \n",
       "10001Z       17/23  S2417  5284  R5277  2455         615  509583.9  6615273.0   \n",
       "\n",
       "              z_s       x_r        y_r   z_r      CDP_X       CDP_Y   azimuth  \\\n",
       "                                                                                \n",
       "FieldRecord                                                                     \n",
       "10001Z       38.1  506859.4  6615497.5  39.9  508221.65  6615385.25  3.059378   \n",
       "10001Z       38.1  510108.2  6614898.0  36.9  509846.05  6615085.50 -0.620881   \n",
       "10001Z       38.1  509258.8  6613398.5  35.4  509421.35  6614335.75 -1.742521   \n",
       "10001Z       38.1  509958.3  6615497.5  37.3  509771.10  6615385.25  0.540145   \n",
       "10001Z       38.1  511507.9  6614898.0  34.8  510545.90  6615085.50 -0.192493   \n",
       "\n",
       "                  offset  \n",
       "                          \n",
       "FieldRecord               \n",
       "10001Z       1366.866901  \n",
       "10001Z        322.302455  \n",
       "10001Z        951.241328  \n",
       "10001Z        218.274832  \n",
       "10001Z        980.102163  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "FieldIndex(index_bin).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or custom shot index to ```FieldIndex```:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>ShotPoint</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FieldRecord</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>42000</td>\n",
       "      <td>1656</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>42000</td>\n",
       "      <td>1657</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>42000</td>\n",
       "      <td>1655</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>42000</td>\n",
       "      <td>1658</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>42000</td>\n",
       "      <td>1654</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            ShotPoint TraceNumber TRACE_SEQUENCE_FILE  \\\n",
       "                                                  raw   \n",
       "FieldRecord                                             \n",
       "111906          42000        1656                   1   \n",
       "111906          42000        1657                   2   \n",
       "111906          42000        1655                   3   \n",
       "111906          42000        1658                   4   \n",
       "111906          42000        1654                   5   \n",
       "\n",
       "                                                     file_id  \n",
       "                                                         raw  \n",
       "FieldRecord                                                   \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "FieldIndex(index_shot).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or ```KNNIndex``` to ```FieldIndex```:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>KNN</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>CDP_X</th>\n",
       "      <th>CDP_Y</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FieldRecord</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>0</td>\n",
       "      <td>1656</td>\n",
       "      <td>499279</td>\n",
       "      <td>6639805</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>0</td>\n",
       "      <td>1657</td>\n",
       "      <td>499304</td>\n",
       "      <td>6639805</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>0</td>\n",
       "      <td>1655</td>\n",
       "      <td>499254</td>\n",
       "      <td>6639805</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>1</td>\n",
       "      <td>1657</td>\n",
       "      <td>499304</td>\n",
       "      <td>6639805</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>1</td>\n",
       "      <td>1656</td>\n",
       "      <td>499279</td>\n",
       "      <td>6639805</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>1</td>\n",
       "      <td>1658</td>\n",
       "      <td>499329</td>\n",
       "      <td>6639805</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>2</td>\n",
       "      <td>1655</td>\n",
       "      <td>499254</td>\n",
       "      <td>6639805</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>2</td>\n",
       "      <td>1656</td>\n",
       "      <td>499279</td>\n",
       "      <td>6639805</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>2</td>\n",
       "      <td>1654</td>\n",
       "      <td>499229</td>\n",
       "      <td>6639805</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            KNN TraceNumber   CDP_X    CDP_Y TRACE_SEQUENCE_FILE  \\\n",
       "                                                             raw   \n",
       "FieldRecord                                                        \n",
       "111906        0        1656  499279  6639805                   1   \n",
       "111906        0        1657  499304  6639805                   2   \n",
       "111906        0        1655  499254  6639805                   3   \n",
       "111906        1        1657  499304  6639805                   2   \n",
       "111906        1        1656  499279  6639805                   1   \n",
       "111906        1        1658  499329  6639805                   4   \n",
       "111906        2        1655  499254  6639805                   3   \n",
       "111906        2        1656  499279  6639805                   1   \n",
       "111906        2        1654  499229  6639805                   5   \n",
       "\n",
       "                                                     file_id  \n",
       "                                                         raw  \n",
       "FieldRecord                                                   \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "FieldIndex(index_knn).head(9)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that the index obtained contains 3 times duplicated traces. To remove them use ```drop_duplicates```:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>KNN</th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>CDP_X</th>\n",
       "      <th>CDP_Y</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FieldRecord</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>0</td>\n",
       "      <td>1656</td>\n",
       "      <td>499279</td>\n",
       "      <td>6639805</td>\n",
       "      <td>1</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>0</td>\n",
       "      <td>1657</td>\n",
       "      <td>499304</td>\n",
       "      <td>6639805</td>\n",
       "      <td>2</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>0</td>\n",
       "      <td>1655</td>\n",
       "      <td>499254</td>\n",
       "      <td>6639805</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>1</td>\n",
       "      <td>1658</td>\n",
       "      <td>499329</td>\n",
       "      <td>6639805</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>2</td>\n",
       "      <td>1654</td>\n",
       "      <td>499229</td>\n",
       "      <td>6639805</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>3</td>\n",
       "      <td>1659</td>\n",
       "      <td>499354</td>\n",
       "      <td>6639805</td>\n",
       "      <td>6</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>4</td>\n",
       "      <td>1653</td>\n",
       "      <td>499204</td>\n",
       "      <td>6639805</td>\n",
       "      <td>7</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>5</td>\n",
       "      <td>1660</td>\n",
       "      <td>499379</td>\n",
       "      <td>6639805</td>\n",
       "      <td>8</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111906</th>\n",
       "      <td>6</td>\n",
       "      <td>1652</td>\n",
       "      <td>499179</td>\n",
       "      <td>6639805</td>\n",
       "      <td>9</td>\n",
       "      <td>/data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            KNN TraceNumber   CDP_X    CDP_Y TRACE_SEQUENCE_FILE  \\\n",
       "                                                             raw   \n",
       "FieldRecord                                                        \n",
       "111906        0        1656  499279  6639805                   1   \n",
       "111906        0        1657  499304  6639805                   2   \n",
       "111906        0        1655  499254  6639805                   3   \n",
       "111906        1        1658  499329  6639805                   4   \n",
       "111906        2        1654  499229  6639805                   5   \n",
       "111906        3        1659  499354  6639805                   6   \n",
       "111906        4        1653  499204  6639805                   7   \n",
       "111906        5        1660  499379  6639805                   8   \n",
       "111906        6        1652  499179  6639805                   9   \n",
       "\n",
       "                                                     file_id  \n",
       "                                                         raw  \n",
       "FieldRecord                                                   \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  \n",
       "111906       /data/NA/noise_dataset_1/DN02A_LIFT_AMPSCAL.sgy  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "FieldIndex(index_knn).drop_duplicates().head(9)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Merge"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Two index instances can be merged on common headers. For example, ```index_ffid``` does not contain offsets. However, we can merge it with ```index_sps``` that includes offsets:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>TraceNumber</th>\n",
       "      <th>TRACE_SEQUENCE_FILE</th>\n",
       "      <th>file_id</th>\n",
       "      <th>sline</th>\n",
       "      <th>sid</th>\n",
       "      <th>rline</th>\n",
       "      <th>rid</th>\n",
       "      <th>point_index</th>\n",
       "      <th>sht_depth</th>\n",
       "      <th>uphole</th>\n",
       "      <th>SourceX</th>\n",
       "      <th>SourceY</th>\n",
       "      <th>z_s</th>\n",
       "      <th>x_r</th>\n",
       "      <th>y_r</th>\n",
       "      <th>z_r</th>\n",
       "      <th>CDP_X</th>\n",
       "      <th>CDP_Y</th>\n",
       "      <th>azimuth</th>\n",
       "      <th>offset</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>raw</th>\n",
       "      <th>raw</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FieldRecord</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "      <td>S37</td>\n",
       "      <td>3591</td>\n",
       "      <td>R37</td>\n",
       "      <td>219</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>338886.78</td>\n",
       "      <td>7033413.0</td>\n",
       "      <td>71.5</td>\n",
       "      <td>338560.00</td>\n",
       "      <td>7029929.5</td>\n",
       "      <td>76.0</td>\n",
       "      <td>338723.39</td>\n",
       "      <td>7031671.25</td>\n",
       "      <td>-1.664331</td>\n",
       "      <td>1749.396855</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "      <td>S37</td>\n",
       "      <td>3591</td>\n",
       "      <td>R37</td>\n",
       "      <td>220</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>338886.78</td>\n",
       "      <td>7033413.0</td>\n",
       "      <td>71.5</td>\n",
       "      <td>338562.40</td>\n",
       "      <td>7029954.5</td>\n",
       "      <td>76.1</td>\n",
       "      <td>338724.59</td>\n",
       "      <td>7031683.75</td>\n",
       "      <td>-1.664315</td>\n",
       "      <td>1736.839416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>3</td>\n",
       "      <td>5</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "      <td>S37</td>\n",
       "      <td>3591</td>\n",
       "      <td>R37</td>\n",
       "      <td>221</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>338886.78</td>\n",
       "      <td>7033413.0</td>\n",
       "      <td>71.5</td>\n",
       "      <td>338564.70</td>\n",
       "      <td>7029979.5</td>\n",
       "      <td>76.2</td>\n",
       "      <td>338725.74</td>\n",
       "      <td>7031696.25</td>\n",
       "      <td>-1.664328</td>\n",
       "      <td>1724.286648</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "      <td>S37</td>\n",
       "      <td>3591</td>\n",
       "      <td>R37</td>\n",
       "      <td>222</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>338886.78</td>\n",
       "      <td>7033413.0</td>\n",
       "      <td>71.5</td>\n",
       "      <td>338567.00</td>\n",
       "      <td>7030004.5</td>\n",
       "      <td>76.8</td>\n",
       "      <td>338726.89</td>\n",
       "      <td>7031708.75</td>\n",
       "      <td>-1.664341</td>\n",
       "      <td>1711.733880</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>/data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy</td>\n",
       "      <td>S37</td>\n",
       "      <td>3591</td>\n",
       "      <td>R37</td>\n",
       "      <td>223</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>338886.78</td>\n",
       "      <td>7033413.0</td>\n",
       "      <td>71.5</td>\n",
       "      <td>338569.38</td>\n",
       "      <td>7030029.0</td>\n",
       "      <td>77.4</td>\n",
       "      <td>338728.08</td>\n",
       "      <td>7031721.00</td>\n",
       "      <td>-1.664317</td>\n",
       "      <td>1699.426283</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            TraceNumber TRACE_SEQUENCE_FILE  \\\n",
       "                                        raw   \n",
       "FieldRecord                                   \n",
       "354                   1                   3   \n",
       "354                   2                   4   \n",
       "354                   3                   5   \n",
       "354                   4                   6   \n",
       "354                   5                   7   \n",
       "\n",
       "                                                       file_id sline   sid  \\\n",
       "                                                           raw               \n",
       "FieldRecord                                                                  \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy   S37  3591   \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy   S37  3591   \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy   S37  3591   \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy   S37  3591   \n",
       "354          /data/NA/2D_Val/prof_37/segy/00000354_f1.r354.sgy   S37  3591   \n",
       "\n",
       "            rline  rid point_index sht_depth uphole    SourceX    SourceY  \\\n",
       "                                                                            \n",
       "FieldRecord                                                                 \n",
       "354           R37  219           1      18.0   14.0  338886.78  7033413.0   \n",
       "354           R37  220           1      18.0   14.0  338886.78  7033413.0   \n",
       "354           R37  221           1      18.0   14.0  338886.78  7033413.0   \n",
       "354           R37  222           1      18.0   14.0  338886.78  7033413.0   \n",
       "354           R37  223           1      18.0   14.0  338886.78  7033413.0   \n",
       "\n",
       "              z_s        x_r        y_r   z_r      CDP_X       CDP_Y  \\\n",
       "                                                                       \n",
       "FieldRecord                                                            \n",
       "354          71.5  338560.00  7029929.5  76.0  338723.39  7031671.25   \n",
       "354          71.5  338562.40  7029954.5  76.1  338724.59  7031683.75   \n",
       "354          71.5  338564.70  7029979.5  76.2  338725.74  7031696.25   \n",
       "354          71.5  338567.00  7030004.5  76.8  338726.89  7031708.75   \n",
       "354          71.5  338569.38  7030029.0  77.4  338728.08  7031721.00   \n",
       "\n",
       "              azimuth       offset  \n",
       "                                    \n",
       "FieldRecord                         \n",
       "354         -1.664331  1749.396855  \n",
       "354         -1.664315  1736.839416  \n",
       "354         -1.664328  1724.286648  \n",
       "354         -1.664341  1711.733880  \n",
       "354         -1.664317  1699.426283  "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_ffid = index_ffid.merge(index_sps)\n",
    "index_ffid.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Enjoy!"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
